home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / graphics / 3dvect30.arj / FILE.ASM < prev    next >
Assembly Source File  |  1993-11-18  |  17KB  |  689 lines

  1. ; this code belongs to TRAN
  2.  
  3.   OPENFILE              = 1
  4.   READFILE              = 1
  5. ; WRITEFILE             = 1
  6. ; LSEEKFILE             = 1
  7. ; CREATEFILE            = 1
  8. ; FILESIZE              = 1
  9. ; FILECOPY              = 1
  10. ; DELETEFILE            = 1
  11. ; FINDFILE              = 1
  12.   ENVIRONMENT           = 1
  13.   FINDMARKER            = 1
  14.  
  15.         .386p
  16.         jumps
  17. code32  segment para public use32
  18.         assume cs:code32, ds:code32
  19.  
  20. include pmode.inc
  21. include macros.inc
  22.  
  23. public  _filebufloc, _filebuflen
  24. public  _closefile
  25.  
  26. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  27. ; DATA
  28. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  29. _filebufloc     dd      0               ; location must be in low mem
  30. _filebuflen     dw      4000h
  31.  
  32. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  33. ; CODE
  34. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  35.  
  36. ifdef   CREATEFILE
  37. public  _createfile
  38. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  39. ; Create file
  40. ; In:
  41. ;   EDX -> ASCIIZ filename
  42. ; Out:
  43. ;   CF=1 - Error creating file
  44. ;   CF=0 - File created succesfully
  45. ;     V86R_BX - file handle
  46. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  47. _createfile:
  48.         push ax
  49.         push edx
  50.         add edx,_code32a
  51.         mov ax,dx
  52.         shr edx,4
  53.         and ax,0fh
  54.         mov v86r_dx,ax
  55.         mov v86r_ds,dx
  56.         mov v86r_ax,3c00h
  57.         mov v86r_cx,20h
  58.         mov al,21h
  59.         int 33h
  60.         mov ax,v86r_ax
  61.         mov v86r_bx,ax
  62.         pop edx
  63.         pop ax
  64.         ret
  65. endif
  66.  
  67. ifdef   OPENFILE
  68. public  _openfile
  69. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  70. ; Open file
  71. ; In:
  72. ;   EDX -> ASCIIZ filename
  73. ; Out:
  74. ;   CF=1 - Error opening file
  75. ;   CF=0 - File opened succesfully
  76. ;     V86R_BX - file handle
  77. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  78. _openfile:
  79.         push ax
  80.         push edx
  81.         add edx,_code32a
  82.         mov ax,dx
  83.         shr edx,4
  84.         and ax,0fh
  85.         mov v86r_dx,ax
  86.         mov v86r_ds,dx
  87.         mov v86r_ax,3d02h
  88.         mov al,21h
  89.         int 33h
  90.         mov ax,v86r_ax
  91.         mov v86r_bx,ax
  92.         pop edx
  93.         pop ax
  94.         ret
  95. endif
  96.  
  97. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  98. ; Close a file
  99. ; In:
  100. ;   V86R_BX - file handle
  101. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  102. _closefile:
  103.         push ax
  104.         mov v86r_ax,3e00h
  105.         mov al,21h
  106.         int 33h
  107.         pop ax
  108.         ret
  109.  
  110. ifdef   DELETEFILE
  111. public  _deletefile
  112. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  113. ; Delete a file
  114. ; In:
  115. ;   EDX -> ASCIIZ filename
  116. ; Out:
  117. ;   CF=1 - Error opening file
  118. ;   CF=0 - File opened succesfully
  119. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  120. _deletefile:
  121.         push ax
  122.         push edx
  123.         add edx,_code32a
  124.         mov ax,dx
  125.         shr edx,4
  126.         and ax,0fh
  127.         mov v86r_dx,ax
  128.         mov v86r_ds,dx
  129.         mov v86r_ah,41h
  130.         mov al,21h
  131.         int 33h
  132.         pop edx
  133.         pop ax
  134.         ret
  135. endif
  136.  
  137. ifdef   LSEEKFILE
  138. public  _lseekfile
  139. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  140. ; Seek position in file
  141. ; In:
  142. ;   V86R_BX - file handle
  143. ;   EAX - signed offset to move to
  144. ;   BL - from: 0-beginning of file, 1-current location, 2-end of file
  145. ; Out:
  146. ;   CF=1  - Error seeking in file
  147. ;     EAX - ?
  148. ;   CF=0  - Seek fine
  149. ;     EAX - new offset from beginning of file
  150. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  151. _lseekfile:
  152.         mov v86r_ah,42h
  153.         mov v86r_al,bl
  154.         mov v86r_dx,ax
  155.         shr eax,16
  156.         mov v86r_cx,ax
  157.         mov al,21h
  158.         int 33h
  159.         pushf
  160.         mov ax,v86r_dx
  161.         shl eax,16
  162.         mov ax,v86r_ax
  163.         popf
  164.         ret
  165. endif
  166.  
  167. ifdef   FILESIZE
  168. public  _filesize
  169. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  170. ; Get size of file
  171. ; In:
  172. ;   V86R_BX - file handle
  173. ; Out:
  174. ;   CF=1  - Error checking file
  175. ;     EAX - ?
  176. ;   CF=0  - chek fine
  177. ;     EAX - size of file
  178. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  179. _filesize:
  180.         mov v86r_ax,4201h
  181.         xor eax,eax
  182.         mov v86r_cx,ax
  183.         mov v86r_dx,ax
  184.         mov al,21h
  185.         int 33h
  186.         push v86r_dx
  187.         push v86r_ax
  188.         mov v86r_ax,4202h
  189.         xor eax,eax
  190.         mov v86r_cx,ax
  191.         mov v86r_dx,ax
  192.         mov al,21h
  193.         int 33h
  194.         mov ax,v86r_dx
  195.         shl eax,16
  196.         mov ax,v86r_ax
  197.         pop v86r_dx
  198.         pop v86r_cx
  199.         mov v86r_ax,4200h
  200.         push eax
  201.         mov al,21h
  202.         int 33h
  203.         pop eax
  204.         ret
  205. endif
  206.  
  207. ifdef   READFILE
  208. public  _readfile
  209. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  210. ; Read from file
  211. ; In:
  212. ;   V86R_BX - file handle
  213. ;   EDX -> buffer to read to
  214. ;   ECX - number of bytes to read
  215. ; Out:
  216. ;   CF=1 - Error reading file
  217. ;     EAX - ?
  218. ;   CF=0 - Read went fine
  219. ;     EAX - number of bytes read
  220. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  221. _readfile:
  222.         pushad
  223.         xor ebp,ebp
  224.         add edx,_code32a
  225.         lea ebx,[ecx+edx]
  226.         cmp ebx,100000h
  227.         ja readlong
  228.         mov eax,edx
  229.         shr eax,4
  230.         and dx,0fh
  231.         mov v86r_ds,ax
  232.         mov v86r_dx,dx
  233. readl:
  234.         mov eax,0fff0h
  235.         cmp eax,ecx
  236.         jbe readlf1
  237.         mov eax,ecx
  238. readlf1:
  239.         mov v86r_cx,ax
  240.         mov v86r_ax,3f00h
  241.         mov al,21h
  242.         int 33h
  243.         jc readdone2
  244.         movzx ebx,v86r_ax
  245.         add ebp,ebx
  246.         sub ecx,ebx
  247.         jbe readdone
  248.         or ebx,ebx
  249.         jz readdone
  250.         add v86r_ds,0fffh
  251.         jmp readl
  252. readlong:
  253.         mov edi,edx
  254.         sub edi,_code32a
  255.         mov edx,ecx
  256.         mov eax,_filebufloc
  257.         add eax,_code32a
  258.         mov ebx,eax
  259.         shr eax,4
  260.         and bx,0fh
  261.         mov v86r_ds,ax
  262.         mov v86r_dx,bx
  263.         movzx ebx,_filebuflen
  264. readlongl:
  265.         mov eax,ebx
  266.         cmp eax,edx
  267.         jbe readlonglf1
  268.         mov eax,edx
  269. readlonglf1:
  270.         mov v86r_cx,ax
  271.         mov v86r_ax,3f00h
  272.         mov al,21h
  273.         int 33h
  274.         jc short readdone2
  275.         movzx ecx,v86r_ax
  276.         add ebp,ecx
  277.         mov eax,ecx
  278.         or eax,eax
  279.         jz readdone
  280.         mov esi,_filebufloc
  281.         rep movsb
  282.         sub edx,eax
  283.         ja readlongl
  284. readdone:
  285.         clc
  286. readdone2:
  287.         mov [esp+28],ebp
  288.         popad
  289.         ret
  290. endif
  291.  
  292. ifdef   WRITEFILE
  293. public  _writefile
  294. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  295. ; Write to file
  296. ; In:
  297. ;   V86R_BX - file handle
  298. ;   EDX -> buffer to write from
  299. ;   ECX - number of bytes to write
  300. ; Out:
  301. ;   CF=1 - Error writing file
  302. ;     EAX - ?
  303. ;   CF=0 - Write went fine
  304. ;     EAX - number of bytes read
  305. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  306. _writefile:
  307.         pushad
  308.         xor ebp,ebp
  309.         add edx,_code32a
  310.         lea ebx,[ecx+edx]
  311.         cmp ebx,100000h
  312.         ja writelong
  313.         mov eax,edx
  314.         shr edx,4
  315.         and ax,0fh
  316.         mov v86r_ds,dx
  317.         mov v86r_dx,ax
  318. writel:
  319.         mov eax,0fff0h
  320.         cmp eax,ecx
  321.         jbe writelf1
  322.         mov eax,ecx
  323. writelf1:
  324.         mov v86r_cx,ax
  325.         mov v86r_ax,4000h
  326.         mov al,21h
  327.         int 33h
  328.         jc writedone2
  329.         movzx ebx,v86r_ax
  330.         add ebp,ebx
  331.         sub ecx,ebx
  332.         jbe writedone
  333.         add v86r_ds,0fffh
  334.         jmp writel
  335. writelong:
  336.         mov esi,edx
  337.         sub esi,_code32a
  338.         mov edx,ecx
  339.         mov eax,_filebufloc
  340.         add eax,_code32a
  341.         mov ebx,eax
  342.         shr eax,4
  343.         and bx,0fh
  344.         mov v86r_ds,ax
  345.         mov v86r_dx,bx
  346.         movzx ebx,_filebuflen
  347. writelongl:
  348.         mov eax,ebx
  349.         cmp eax,edx
  350.         jbe writelonglf1
  351.         mov eax,edx
  352. writelonglf1:
  353.         mov ecx,eax
  354.         mov edi,_filebufloc
  355.         rep movsb
  356.         mov v86r_cx,ax
  357.         mov v86r_ax,4000h
  358.         mov al,21h
  359.         int 33h
  360.         jc writedone2
  361.         movzx ecx,v86r_ax
  362.         add ebp,ecx
  363.         sub edx,ecx
  364.         ja writelongl
  365. writedone:
  366.         clc
  367. writedone2:
  368.         mov [esp+28],ebp
  369.         popad
  370.         ret
  371. endif
  372.  
  373. ifdef   FILECOPY
  374. public  _filecopy
  375. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  376. ; Copy some bytes from one file to another
  377. ; In:
  378. ;   V86R_SI - source file handle
  379. ;   V86R_DI - destination file handle
  380. ;   ECX - number of bytes to copy
  381. ; Out:
  382. ;   CF=1  - Error copying file
  383. ;     EAX - ?
  384. ;   CF=0  - copied fine
  385. ;     EAX - number of bytes copied
  386. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  387. _filecopy:
  388.         pushad
  389.         xor ebp,ebp
  390.         mov edx,_filebufloc
  391.         add edx,_code32a
  392.         mov al,dl
  393.         and ax,0fh
  394.         shr edx,4
  395.         mov v86r_ds,dx
  396.         mov v86r_dx,ax
  397.         movzx ebx,_filebuflen
  398. copylongl:
  399.         mov eax,ebx
  400.         cmp eax,ecx
  401.         jbe copylonglf1
  402.         mov eax,ecx
  403. copylonglf1:
  404.         mov v86r_cx,ax
  405.         mov v86r_ax,3f00h
  406.         mov ax,v86r_si
  407.         mov v86r_bx,ax
  408.         mov al,21h
  409.         int 33h
  410.         jc copydone2
  411.         mov ax,v86r_ax
  412.         or ax,ax
  413.         jz copydone
  414.         mov v86r_cx,ax
  415.         mov v86r_ax,4000h
  416.         mov ax,v86r_di
  417.         mov v86r_bx,ax
  418.         mov al,21h
  419.         int 33h
  420.         jc copydone2
  421.         movzx edx,v86r_ax
  422.         add ebp,edx
  423.         sub ecx,edx
  424.         ja copylongl
  425. copydone:
  426.         clc
  427. copydone2:
  428.         mov [esp+28],ebp
  429.         popad
  430.         ret
  431. endif
  432.  
  433. ifdef   FINDFILE
  434. public  _findfile
  435. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  436. ; Do an AH=4E findfirst
  437. ; In:
  438. ;   AL - type of search: 4E-first, 4F-next
  439. ;   CX - search attributes
  440. ;   EDX -> 13 byte buffer for filename found
  441. ;   EDI -> search mask
  442. ; Out:
  443. ;   CF=1 - file not found
  444. ;     [EDX] - ?
  445. ;   CF=0 - file found
  446. ;     [EDX] - filename
  447. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  448. _findfile:
  449.         push eax
  450.         push esi
  451.         push edi
  452.         add edi,_code32a
  453.         mov esi,edi
  454.         and esi,0fh
  455.         shr edi,4
  456.         mov v86r_ds,di
  457.         mov v86r_dx,si
  458.         mov v86r_ah,al
  459.         mov v86r_cx,cx
  460.         mov esi,_code16a
  461.         sub esi,62h
  462.         mov edi,edx
  463.         mov al,21h
  464.         int 33h
  465.         mov ax,gs
  466.         mov ds,ax
  467.         movsd
  468.         movsd
  469.         movsd
  470.         movsb
  471.         mov ax,es
  472.         mov ds,ax
  473.         pop edi
  474.         pop esi
  475.         pop eax
  476.         ret
  477. endif
  478.  
  479. ifdef   ENVIRONMENT
  480.  
  481. ; the following routines are by Alan Illeman
  482.  
  483.         public setup_env
  484.  
  485.         public localpath
  486.         public envirpath
  487.         public progname
  488.  
  489. setup_env:
  490.  
  491.         push    esi edi
  492. ;--------------------------------------
  493. ; get environment path, program name
  494. ;--------------------------------------
  495.         mov     edi, _pspa
  496.         sub     edi, _code32a
  497.         movzx   eax, word ptr [edi]+2Ch
  498.         @segoff2ptr edi, eax, 0
  499.  
  500.         mov     ecx, 32768
  501.         mov     al, 1
  502.         cld
  503.         repne   scasb
  504.         inc     edi
  505.         mov     esi, edi
  506.         mov     edi, offset envirpath
  507. envir1:
  508.         lodsb
  509.         stosb
  510.         cmp     al, '\'
  511.         jne     envir2
  512.         mov     ebx, esi
  513. envir2:
  514.         or      al, al
  515.         jnz     envir1
  516. ;--------------------------------------
  517. ; save program name
  518. ;--------------------------------------
  519.         mov     esi, ebx
  520.         mov     edi, offset progname
  521. envir3:
  522.         lodsb
  523.         stosb
  524.         or      al, al
  525.         jnz     envir3
  526.  
  527. ;--------------------------------------
  528. ; get local path
  529. ;--------------------------------------
  530.         mov     edi, offset localpath
  531.  
  532.         mov     v86r_ah, 19h              ; get current disk
  533.         mov     al, 21h                   ; doscall
  534.         int     33h
  535.         mov     al, v86r_al               ; 0=A, 1=B, 2=C, etc
  536.  
  537.         mov     dl, al
  538.         inc     dl
  539.         add     al, 'A'                   ; drive letter
  540.         stosb
  541.         mov     al, ':'                   ; colon
  542.         stosb
  543.         mov     al, '\'                   ; backslash
  544.         stosb
  545.  
  546.         @ptr2segoff edi, ebx, eax
  547.         mov     v86r_ds, bx
  548.         mov     v86r_si, ax
  549.  
  550.         mov     v86r_ah, 47h              ; get current directory
  551.         mov     v86r_dl, dl               ; DL = disk
  552.         mov     al, 21h                   ; doscall
  553.         int     33h
  554.  
  555.         cmp     byte ptr [edi], 0         ; no directory ?
  556.         je      local1                    ; yes, exit
  557.  
  558.         mov     edi, offset localpath
  559.         mov     ecx, 127
  560.         add     edi, ecx
  561.         xor     al, al
  562.         std
  563.         repe    scasb
  564.         cld
  565.         inc     edi
  566.         inc     edi
  567.  
  568.         mov     al, '\'                   ; final backslash
  569.         stosb
  570. local1:
  571.         xor     al, al                    ; null termination
  572.         stosb
  573.  
  574.         pop     edi esi
  575.         ret
  576.  
  577. ; this is what the above routine sets up for you:
  578.  
  579. localpath db 160 dup(0)  ; current directory with "\" and terminating 0, eg c:\download\@
  580. envirpath db 160 dup(0)  ; directory where program is (along with program name) eg c:\dir\prog.exe@
  581. progname  db 16 dup(0)   ; program name with terminating 0  eg prog.exe@
  582.  
  583.         endif
  584.  
  585. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  586. ; find "[MARKER]"+text in file:
  587. ;
  588. ; ECX -> marker text to find.  text is null terminated. max 32 characters
  589. ; EDX -> ASCIIZ filename
  590. ;
  591. ; return:
  592. ;
  593. ; EAX = position in file where marker found
  594. ;  CF=1  - Error seeking in file or marker not found
  595. ;  CF=0  - Seek fine
  596. ;
  597. ; eg:dw x,x,x,x,"[MARKER]databeginshere"
  598. ;    dw 0,0,0,0  <- eax will point to this position in file if you seek for "databeginshere"
  599. ;
  600. ; I will use this to store all my data (mods, gifs etc...) at the end  of  the
  601. ; executable.  when the appropriate data is required, search the program  name
  602. ; for the mod or gif required.  this then returns a seek position to load that
  603. ; mod   or     gif    from.     after    assembling    the    main    program,
  604. ; copy /b yourprog.exe+marker.txt+data.dat  to concatenate the  data   to  the
  605. ; executable.  where marker.txt = "[MARKER]thing" and you search for  "thing".
  606. ; eax will then point to where data.dat is in yourprog.exe
  607. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  608. ifdef   FINDMARKER
  609.  
  610.         public _findmarker
  611.  
  612. _findbuflen equ 64
  613.  
  614. _findmarker:
  615.  
  616.         pushad
  617.         call _openfile
  618.         jc _ferror
  619.         popad
  620.         pushad
  621.  
  622.         mov esi,ecx
  623.         mov ecx,32
  624.         mov edi,offset _lookfor
  625.         rep movsb        ; move text into buffer
  626.  
  627.         mov edx, offset _findbuffer1
  628.         mov ecx, _findbuflen*2
  629.         call _readfile
  630.         jc _ferror
  631.  
  632.         xor esi,esi
  633.         xor edi,edi
  634.         xor ebp,ebp
  635.  
  636. _scanloop:
  637.         mov al,_search[esi]
  638.         or al,al
  639.         jz _foundit
  640.         cmp _findbuffer1[edi],al
  641.         je _next
  642.         mov esi,-1
  643. _next:
  644.         inc esi
  645.         inc edi
  646.         inc ebp
  647.         cmp edi,_findbuflen
  648.         jne _scanloop
  649.  
  650.         push esi
  651.         mov ecx,_findbuflen
  652.         mov esi,offset _findbuffer2
  653.         mov edi,offset _findbuffer1
  654.         rep movsb
  655.         pop esi
  656.  
  657.         mov edx, offset _findbuffer2
  658.         mov ecx,_findbuflen
  659.         push ebp
  660.         call _readfile
  661.         pop ebp
  662.         jc _ferror
  663.         cmp eax,0
  664.         stc
  665.         je _ferror
  666.  
  667.         xor edi,edi
  668.         jmp _scanloop
  669.  
  670. _foundit:
  671.         mov [esp+28],ebp
  672.         clc
  673. _ferror:
  674.         pushf
  675.         call _closefile
  676.         popf
  677.         popad
  678.         ret
  679.  
  680. _search      db "[MARKER]"
  681. _lookfor     db _findbuflen dup (0)
  682. _findbuffer1 db _findbuflen dup (0)
  683. _findbuffer2 db _findbuflen dup (0)
  684.  
  685.         endif
  686.  
  687. code32  ends
  688.         end
  689.